package com.noah.project.controller

import com.noah.project.global.Const
import com.noah.project.model.Book
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

@RunWith(SpringRunner::class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class BookApiControllerTest {
    @Autowired
    lateinit var bookController: BookApiController
    /*****************日记本******************/
    @Test
    @Throws(Exception::class)
    fun addBook() {
        val book = Book(uid = 1, title = "测试日记本", msg = "第一本书...")
        val reply = bookController.addBook(book, Const.TEST_TOKEN)
        println(reply.toString())
    }

    @Test
    @Throws(Exception::class)
    fun deleteBook() {
        val reply = bookController.deleteBook(4, Const.TEST_TOKEN)
        println(reply.toString())
    }

    @Test
    @Throws(Exception::class)
    fun update() {
        val book = Book(bid = 1, uid = 1, title = "修改测试日记本", msg = "修改了谢谢")
        val reply = bookController.updateBook(book, Const.TEST_TOKEN)
        println(reply.toString())
    }

    @Test
    @Throws(Exception::class)
    fun getBook() {
        val reply = bookController.getBook(1, Const.TEST_TOKEN)
        println(reply.toString())
    }

    @Test
    @Throws(Exception::class)
    fun getUserBooks() {
        val reply = bookController.getBookList(1, Const.TEST_TOKEN)
        println(reply.toString())
    }
}
